<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="../vue.js"></script>
  </head>
  <body>
    <div id="app">
      <button @click="update1">使用变更方法修改数组</button>
      <button @click="update2">使用非变更方法修改数组</button>
      <ul>
        <li v-for="item in arr">{{item}}</li>
      </ul>
    </div>

    <script>
      Vue.config.productionTip = false;

      const vm = new Vue({
        el: "#app",
        data() {
          return {
            arr: ["王哥", "小哥", "老王"],
          };
        },
        methods: {
          update1() {
            /* Vue 将被侦听的数组的变更方法进行了包裹，所以它们也将会触发视图更新 */
            this.arr.sort();
          },
          update2() {
            this.arr = this.arr.filter((item) => {
              return item !== "小哥";
            });
          },
        },
      });
    </script>
  </body>
</html>
